<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="UTF-8">
	<title>个人信息</title>
	<meta name="renderer" content="webkit">	
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">	
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">	
	<meta name="apple-mobile-web-app-status-bar-style" content="black">	
	<meta name="apple-mobile-web-app-capable" content="yes">	
	<meta name="format-detection" content="telephone=no">	
	<link rel="stylesheet" type="text/css" th:href="@{common/layui/css/layui.css}" href="common/layui/css/layui.css" media="all">
	<link rel="stylesheet" type="text/css" th:href="@{common/bootstrap/css/bootstrap.css}" href="common/bootstrap/css/bootstrap.css" media="all">
	<link rel="stylesheet" type="text/css" th:href="@{common/global.css}" href="common/global.css" media="all">
	<link rel="stylesheet" type="text/css" th:href="@{css/personal.css}" href="css/personal.css" media="all">
</head>
<body>
<section class="layui-larry-box">
	<div class="larry-personal">
		<header class="larry-personal-tit">
			<span>修改密码</span>
		</header><!-- /header -->
		<div class="larry-personal-body clearfix changepwd">
			<form class="layui-form col-lg-4" method="post" th:id="changepwdform" th:action="@{/user/update}" action="">
				<div hidden="hidden"><input name="uId" class="layui-input" th:value="${session.loginUser.uId}"></div>
				<div class="layui-form-item">
					<label class="layui-form-label">用户名</label>
					<div class="layui-input-block">  
					  	<input type="text" name="username"  autocomplete="off"  class="layui-input " th:placeholder="${session.loginUser.username}" th:value="${session.loginUser.username}" value="admin"  >
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">旧密码</label>
					<div class="layui-input-block">  
					  	<input type="password" name="title"  autocomplete="off"  class="layui-input layui-disabled" value="" th:placeholder="${session.loginUser.password}" disabled="disabled">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">新密码</label>
					<div class="layui-input-block">  
					  	<input type="password" name="password"  autocomplete="off"  class="layui-input"  placeholder="请输入新密码">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">确认密码</label>
					<div class="layui-input-block">  
					  	<input type="password" name="password2"  autocomplete="off"  class="layui-input"  placeholder="请输入确认新密码">
					</div>
				</div>
				<div class="layui-form-item change-submit">
					<div class="layui-input-block">
						<button id="submit" type="button" class="layui-btn" onsubmit="false" lay-submit="" lay-filter="demo1">立即提交</button>
						<button type="reset" class="layui-btn layui-btn-primary">重置</button>
					</div>
				</div>
			</form>
		</div>
	</div>
</section>
<script type="text/javascript" th:src="@{/easyui/jquery-1.8.0.min.js}"></script>
<link rel="stylesheet" type="text/css" th:href="@{/easyui/themes/default/easyui.css}">
<link rel="stylesheet" type="text/css" th:href="@{/easyui/themes/icon.css}">
<script type="text/javascript" th:src="@{/easyui/jquery.easyui.min.js}"></script>
<script type="text/javascript" th:src="@{common/layui/layui.js}" src="common/layui/layui.js"></script>
<script type="text/javascript">
	layui.use(['form','upload'],function(){
         var form = layui.form();
	});

    function sleep(n) { //n表示的毫秒数
        var start = new Date().getTime();
        while (true) if (new Date().getTime() - start > n) break;
    }

	//提交修改密码表单
    //登录链接测试，使用时可删除
    $(function () {
        //绑定提交按钮
        $("#submit").click(function () {
            var username = $(" input[ name='username' ] ").val().trim();
            var password = $(" input[ name='password' ] ").val().trim();
            var password2 = $(" input[ name='password2' ] ").val().trim();
            // alert(password)
            // alert(password2)
            // alert(password2 == password)
            if(password == password2) {
                if(username.length == 0 || password.length == 0) {
                    $.messager.alert("提示","未填用户名或密码","error");
                }else {
                    var targetUrl = $("#changepwdform").attr("action");
                    var data = $("#changepwdform").serialize();


                    $.ajax({
                        type:'post',
                        url:targetUrl,
                        cache: false,
                        data:data,  //重点必须为一个变量如：data
                        dataType:'json',
                        success:function(data){
                            // alert("zzz");
                            if(data == 1) {
                               //alert("更新成功");
                                //刷新界面
                                alert("更新成功,请重新登录");
                                // sleep(3000);

                                top.location.reload();

                            }

                            if(data == 0) {
                                //alert("更新失败");
                                $.messager.alert("提示","更新失败","error");
                            }

                        },
                        error:function(){
                            $.messager.alert("提示","请求失败","error");
                        }
                    })
                }
            }else {
                $.messager.alert("提示","两次密码不一致","error");
            }

        });
    });


</script>
</body>
</html>